package com.zg.shop.categorysecond;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zg.shop.category.Category;
import com.zg.shop.category.CategoryAction;
import com.zg.shop.category.CategoryService;
import com.zg.shop.product.PageBean;


public class CategorySecondAction extends ActionSupport implements ModelDriven<CategorySecond>{
	private Integer page;
	private CategorySecondService categorySecondService;
	private CategoryService categoryService;
	private Integer cid;
	private CategorySecond categorySecond = new CategorySecond();
	private Integer csid;

	public void setCsid(Integer csid) {
		this.csid = csid;
	}
	@Override
	public CategorySecond getModel() {
		return categorySecond;
	}
	public void setCid(Integer cid) {
		this.cid = cid;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public void setCategorySecondService(CategorySecondService categorySecondService) {
		this.categorySecondService = categorySecondService;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public String adminFindAll(){
		PageBean<CategorySecond> pageBean = categorySecondService.findByPage(page);
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "adminFindAllSuccess";
	}
	
	public String addPage(){
		//查询一级分类的列表
		List<Category> categorys = categoryService.findAll();
		ActionContext.getContext().getValueStack().set("categorys", categorys);
		
		return "addPageSuccess";
	}
	
	public String save(){
		Category category = new Category();
		category.setCid(cid);
		categorySecond.setCategory(category);
		categorySecondService.save(categorySecond);
		return "saveSuccess";
	}

	public String delete(){
		categorySecondService.delete(categorySecond);
		return "deleteSuccess";
	}
	public String edit(){
		
		categorySecond = categorySecondService.findByCsid(categorySecond.getCsid());
		
		return "editSuccess";
	}
	
	public String update(){
		//Category category = categoryService.findByCid(cid);
		//categorySecond.setCategory(category);
		//categorySecond.setCsid(csid);
		//Category category = new Category();
//		category.setCid(cid);
//		categorySecond.setCategory(category);
/*		categorySecondService.update(categorySecond);*/
		return "udpateSuccess";
	}
}
